var orderNo = getValueByParam('orderNo'),
	fileList = [];

$(() => {
	initRater();
	loadData();
	initListener();
})

initRater = () => {
	$(`.rating-stars-container`).html('');
	for (var i = 0; i < 5; i++) {
		let itemHtml = `<div class="rating-star">
									<i class="fa fa-star"></i>
								</div>`;
		$(`.rating-stars-container`).append(itemHtml);
	}
	var ratingOptions = {
		selectors: {
			starsSelector: '.rating-stars',
			starSelector: '.rating-star',
			starActiveClass: 'is--active',
			starHoverClass: 'is--hover',
			starNoHoverClass: 'is--no-hover',
			targetFormElementSelector: '.rating-value'
		}
	};
	$(".rating-stars").ratingStars(ratingOptions);
}

initListener = () => {
	$(".textarea").bind('input propertychange', (event) => {
		let value = event.target.value;
		$(`.input_tip_box`).html(value.length + '/' + event.target.maxLength);
	});
	$(".file_input").bind('input propertychange', (event) => {
		handlePickFile(fileList, 9, 'file_add', 'pick_file', 'evaluateFile', 'evaluateName',
			'evaluateOrder',
			event, (res) => {
				fileList = res
			});
	});
	// $("#pick_file").on('change', (file) => {
	// 	event.stopPropagation();
	// 	handlePickFile(fileList, 9, 'file_add', 'pick_file', 'classroomFile', 'classroomName', 'classroom',
	// 		file, (res) => {
	// 			fileList = res
	// 		});
	// });
	$("#save").on('click', () => {
		onSubmit();
	});
}

onSubmit = () => {
	let evaluate_goods = $(`#evaluate_goods`).val();
	let evaluate_logistics = $(`#evaluate_logistics`).val();
	let evaluate_service = $(`#evaluate_service`).val();
	let evaluateContent = $(`.textarea`).val();
	let anonymous = $(`.check_anonymous`)[0].checked;
	if (evaluateContent == '') {
		showToast('请输入评价内容');
		$(`.textarea`).focus();
		return
	}
	let subLoading = layer.open({
		type: 2,
		shadeClose: false,
		content: '正在提交...'
	});
	setTimeout(() => {
		layer.close(subLoading);
		showToast('提交成功！');
		goBack();
	}, 500)
}

loadData = () => {
	queryOrderDetail(orderNo, res => {
		setOrderList(res);
	})
}

setOrderList = (data) => {
	let mlist = data.orderItemVOs;
	$(`#goods_list`).html('');
	let itemHtml = ``;
	for (var i = 0; i < mlist.length; i++) {
		let childObj = mlist[i];
		itemHtml += `<div class="order_item_child">
						<img src="${childObj.goodsPictureUrl}" class="order_img" />
						<div class="order_content">
							<span class="title">${childObj.goodsName}</span>
							<span class="des">${childObj.specifications[0].specValue},${childObj.specifications[1].specValue}</span>
						</div>
						<div class="order_price">
							<div class="goods_price">
								<span class="unit">¥</span>
								<span class="price">${childObj.actualPrice}</span>
							</div>
							<div class="goods_quantity">
								<span class="unit">X</span>
								<span class="num">${childObj.buyQuantity}</span>
							</div>
						</div>
					</div>`;
	}
	$(`#goods_list`).html(itemHtml);
}
